﻿using System;
using Microsoft.EntityFrameworkCore.Migrations;

#nullable disable

namespace Himp.Erp.Migrations
{
    /// <inheritdoc />
    public partial class remove_table_DrugBasInfoAssocChrgitmType : Migration
    {
        /// <inheritdoc />
        protected override void Up(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MaterialWhses_MaterialWhses_MaterialWhseId",
                schema: "Erp",
                table: "MaterialWhses");

            migrationBuilder.DropTable(
                name: "DrugBasInfoAssocChrgitmType",
                schema: "Erp");

            migrationBuilder.DropTable(
                name: "DrugMedcWayGrp",
                schema: "Erp");

            migrationBuilder.RenameColumn(
                name: "MaterialWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                newName: "MatlWhseId");

            migrationBuilder.RenameIndex(
                name: "IX_MaterialWhses_MaterialWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                newName: "IX_MaterialWhses_MatlWhseId");

            migrationBuilder.CreateTable(
                name: "DrugCatalogAssocChrgitmType",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugCatalogId = table.Column<Guid>(type: "uuid", nullable: false),
                    ClncChrgitmTypeCode = table.Column<string>(type: "text", nullable: false),
                    ClncChrgitmTypeName = table.Column<string>(type: "text", nullable: false),
                    HiChrgitmTypeCode = table.Column<string>(type: "text", nullable: true),
                    HiChrgitmTypeName = table.Column<string>(type: "text", nullable: true),
                    MedcasChrgitmTypeCode = table.Column<string>(type: "text", nullable: true),
                    MedcasChrgitmTypeName = table.Column<string>(type: "text", nullable: true),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugCatalogAssocChrgitmType", x => x.Id);
                    table.ForeignKey(
                        name: "FK_DrugCatalogAssocChrgitmType_DrugCatalog_DrugCatalogId",
                        column: x => x.DrugCatalogId,
                        principalSchema: "Erp",
                        principalTable: "DrugCatalog",
                        principalColumn: "Id",
                        onDelete: ReferentialAction.Cascade);
                });

            migrationBuilder.CreateIndex(
                name: "IX_DrugCatalogAssocChrgitmType_DrugCatalogId",
                schema: "Erp",
                table: "DrugCatalogAssocChrgitmType",
                column: "DrugCatalogId",
                unique: true);

            migrationBuilder.AddForeignKey(
                name: "FK_MaterialWhses_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                column: "MatlWhseId",
                principalSchema: "Erp",
                principalTable: "MaterialWhses",
                principalColumn: "Id");
        }

        /// <inheritdoc />
        protected override void Down(MigrationBuilder migrationBuilder)
        {
            migrationBuilder.DropForeignKey(
                name: "FK_MaterialWhses_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "MaterialWhses");

            migrationBuilder.DropTable(
                name: "DrugCatalogAssocChrgitmType",
                schema: "Erp");

            migrationBuilder.RenameColumn(
                name: "MatlWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                newName: "MaterialWhseId");

            migrationBuilder.RenameIndex(
                name: "IX_MaterialWhses_MatlWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                newName: "IX_MaterialWhses_MaterialWhseId");

            migrationBuilder.CreateTable(
                name: "DrugBasInfoAssocChrgitmType",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    ChrgitmTypeId = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugBasInfoId = table.Column<Guid>(type: "uuid", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugBasInfoAssocChrgitmType", x => x.Id);
                });

            migrationBuilder.CreateTable(
                name: "DrugMedcWayGrp",
                schema: "Erp",
                columns: table => new
                {
                    Id = table.Column<Guid>(type: "uuid", nullable: false),
                    DrugMedcWayCatgeCode = table.Column<string>(type: "text", nullable: false),
                    DrugMedcWayCodg = table.Column<string>(type: "text", nullable: false),
                    DrugMedcWayName = table.Column<string>(type: "text", nullable: false),
                    TenantId = table.Column<Guid>(type: "uuid", nullable: true)
                },
                constraints: table =>
                {
                    table.PrimaryKey("PK_DrugMedcWayGrp", x => x.Id);
                });

            migrationBuilder.AddForeignKey(
                name: "FK_MaterialWhses_MaterialWhses_MaterialWhseId",
                schema: "Erp",
                table: "MaterialWhses",
                column: "MaterialWhseId",
                principalSchema: "Erp",
                principalTable: "MaterialWhses",
                principalColumn: "Id");
        }
    }
}
